package ui;

import java.awt.Container;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;

import network.NetworkVars;

import core.Phrox;

public class PopUp extends JFrame implements ActionListener{

	
	public static void main(String[] args){
		new PopUp(Phrox.name,Phrox.p_ShortInfo());
	}
	
	public PopUp(String title, String text){
		setTitle(title);
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		//setResizable(false);
		
		ImageIcon i = new ImageIcon(core.Phrox.rootDir+Gui.thumbNail);
		setIconImage(i.getImage());
		setSize(310,175);
		Container pane = this.getContentPane();
		
		pane = new Container();
		pane = getContentPane();
		pane.setLayout(null);
		
		JTextArea label = new JTextArea(text);
		label.setLayout(null);
		label.setEditable(false);
		label.setWrapStyleWord(true);
		label.setBounds(25, 0, getWidth()-50, getHeight()-75);
		pane.add(label);
		
		JButton b = new JButton("Ok");
		b.setBounds(getWidth()-130, getHeight()-70, 100, 30);
		b.setLayout(null);
		b.addActionListener(this);
		pane.add(b);
		
		//this.setLocation( (Toolkit.getDefaultToolkit().getScreenSize().width-getWidth())/2, (Toolkit.getDefaultToolkit().getScreenSize().height-getHeight())/2);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setResizable(false);
		setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getActionCommand().equals("Ok")){
			this.dispose();
			this.removeAll();
		}
		
	}

	/**
	 * This method blocks, and waits for the user to hit the ok button.
	 * @param title title of the popup window
	 * @param text text contained in the popup window
	 */
	public static void showPopUp(String ti, String tx){
		PopUp p = new PopUp(ti,tx);
		while( p.isDisplayable() ){
			try {
				Thread.sleep(NetworkVars.defSleep);
			} catch (InterruptedException e) {}
		}
		p.dispose();
	}
	
}
